/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFPDCL
  \brief for DCs around the target. PDCR is Proton DC the Right, constructed in
  Japan and reused by BUAA.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-10-31
  \date 2021-11-09 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-10-31   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <cmath>
#include "ETFPDCL.h"

ETFPDCL::ETFPDCL(const char *name) : ETFPDC(name){
  for(const auto &chid : fChIdConfig){
    FillChIdMap(chid.as<int>());
    type[0]++; // 0: X; 1: Y
  } // end for over cables

  // configure the DC //
  fLayerSpaceXY = -20.;
} // end ctor

ETFPDCL::~ETFPDCL(){}

// fill the channel map for X or Y wires
void ETFPDCL::FillChIdMap(int chId0){
  if(chId0 < 0) return;
  for(int i = 0; i < 2; i++) for(int j = 0; j < fNL; j++)
    //            chanel id         X-Y  X1-2 wireId
    SetChMap(chId0+1-i+2*j, uid(type[0], i, j));
} // end member function FillCableChMap

// r = r(t); drift distance - drift time relation
double ETFPDCL::SpaceTimeRelation(double t){
  // usually STR at different HVs are so different as worth special treatment
  // be it a garfield simulation, or user-refined tuning based on experiment data analysis
  double r = 0.;
  const int POLN = fvstr.size();

  if(!POLN) r = ETFVDC::SpaceTimeRelation(t); // a parabola-form STR
  else for(int i = POLN; i--;) r += fvstr[i]*pow(t, i);
  if(r < 0. || t < -10.) r = 0.;
  if(r > fMaxDL || t > 550.) r = fMaxDL;

  return r;
} // end member function SpaceTimeRelation
